﻿using System.Drawing.Imaging;
using Microsoft.AspNetCore.Mvc;

namespace V6.validate_code_core.web.Controllers
{
    public class get_verify_codeController : Controller
    {
        // GET: /get_verify_code
        public IActionResult Index()
        {
            string code = VerifyCode.NextCode(6);
            HttpContext.Session.SetString("ValidateCode", code);

            using (var ms = new MemoryStream())
            {
                using (var image = VerifyCode.NextImage(code))
                {
                    image.Save(ms, ImageFormat.Jpeg);
                    ms.Seek(0, SeekOrigin.Begin);
                    return File(ms.ToArray(), "image/jpeg");
                }
            }
        }
    }
}
